//
//  WebServer.h
//  Phidgets
//
//  Created by Daniel Hazelbaker on 11/5/11.
//  Copyright 2011 Blue Box Moon. All rights reserved.
//

#ifndef __WEBSERVER_H__
#define __WEBSERVER_H__

#include "mongcpp.h"
#include "Utils.h"
#include "WebHandler.h"


//
// Define the map that will hold the list of URI's we call.
//
typedef std::list<WebHandler> WebServerHandlers;


class WebServer : public mongoose::MongooseServer
{
private:
    WebServerHandlers   _handlers;

public:
    WebServer(std::string document_root);
    virtual ~WebServer() { }
    
    void RegisterHandler(std::string uri, std::string method, WebServerHandler handlerMethod);
    
protected:
    virtual bool handleEvent(mongoose::ServerHandlingEvent eventCode, mongoose::MongooseConnection &connection, const mongoose::MongooseRequest &request, mongoose::MongooseResponse &response);

    bool MatchRequest(const std::string &uri, const std::string &handlerUri, StringDictionary &values) const;
    const std::string getRequestValue(const mongoose::MongooseRequest &request, std::string key);
};


#endif /* __WEBSERVER_H__ */

